﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using mfe.bll;

namespace mfe_proj.Forms
{
    public partial class WebsiteForm : BaseDetailForm
    {
        public ItemWebsite website = null;
        string _ItemGuidID;
        public string ItemGuidID { get { return _ItemGuidID; } set { _ItemGuidID = value; } }

        public WebsiteForm()
        {
            InitializeComponent();
        }

        public override string ValidateData()
        {
            return "";
        }

        public override bool SaveData(string itemGuidID)
        {
            bool retval = false;
            try
            {
                //general
                if (website == null)
                {
                    website = new ItemWebsite();
                    website.ItemWebsiteGuidID = Guid.NewGuid().ToString();
                }
                website.ItemGuidID = itemGuidID;
                website.AdminEmail = txtAdminEmail.Text.Trim();
                website.AdminName = txtAdminName.Text.Trim();
                website.WebsiteUrl = txtURL.Text.Trim();
                if (ymdEstablish.Year.HasValue)
                    website.EstablishedYear = ymdEstablish.Year.Value;
                if (ymdEstablish.Month.HasValue)
                    website.EstablishedMonth = ymdEstablish.Month.Value;
                if (ymdEstablish.Day.HasValue)
                    website.EstablishedDay = ymdEstablish.Day.Value;
                if (ymdClosed.Year.HasValue)
                    website.ClosedYear = ymdClosed.Year.Value;
                if (ymdClosed.Month.HasValue)
                    website.ClosedMonth = ymdClosed.Month.Value;
                if (ymdClosed.Day.HasValue)
                    website.ClosedDay = ymdClosed.Day.Value;
                website.Note = txtNote.Text.Trim();
                //save
                retval = (website.WebsiteID == 0) ? website.Save() : website.Update();
            }
            catch (Exception ex)
            {
                mfe.lib.Logger.Log(ex);
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return retval;
        }

        public Panel DockablePanel
        {
            get { return panel1; }
            set { panel1 = value; }
        }
    }
}
